<html> 
<!--
/*!
 *
 * Bancha Project : Combining Ext JS and CakePHP (http://banchaproject.org)
 * Copyright 2011-2012 StudioQ OG
 *
 * @package       Bancha
 * @copyright     Copyright 2011-2012 StudioQ OG
 * @link          http://banchaproject.org Bancha Project
 * @since         Bancha v 0.9.3
 * @author        Roland Schuetz <mail@rolandschuetz.at>
 * @version       Bancha v 1.2.3
 *
 * For more information go to http://banchaproject.org 
 */
-->
<head>
<title>Bancha Project - Combining ExtJS and CakePHP</title> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<meta http-equiv="Content-Style-Type" content="text/css" /> 
<meta http-equiv="Content-Script-Type" content="text/javascript" /> 
<meta name="description" content="" /> 
<meta name="keywords" content="" /> 
<link href='http://fonts.googleapis.com/css?family=Droid+Serif:regular,bold' rel='stylesheet' type='text/css' /> 
<!-- 1140px Grid styles for IE --> 
<!--[if lte IE 9]><link rel="stylesheet" href="http://banchaproject.org//tl_files/Bancha/styles/ie.css" type="text/css" media="screen" /><![endif]--> 
<!-- The 1140px Grid - http://cssgrid.net/ --> 
<link rel="stylesheet" href="http://banchaproject.org//tl_files/Bancha/styles/1140.css" type="text/css" media="screen" /> 
<!--css3-mediaqueries-js - http://code.google.com/p/css3-mediaqueries-js/ - Enables media queries in some unsupported browsers--> 
<script type="text/javascript" src="http://banchaproject.org//tl_files/Bancha/scripts/css3-mediaqueries.js"></script> 
<link rel="stylesheet" href="http://banchaproject.org//tl_files/Bancha/styles/master.css" type="text/css" media="screen" /> 
<meta name="robots" content="index,follow" />
<!--[if lte IE 7]><link rel="stylesheet" href="http://banchaproject.org/system/iefixes.css" type="text/css" media="screen" /><![endif]-->

<style type="text/css">
	#log {
		width: 650;
		min-height:300px;
		margin: auto;
		padding:10px;
		border:1px solid black;
	
		text-align:left;
		font-size:13px;
		color: black;
	}
	#log img {
		vertical-align:bottom;
	}
	#log .explanation {
		font-style: italic;
		margin-left:18px;
	}
</style>
</head>
<body id="top" style="text-align:center;"> 
<div class="wrapper">
    <br />
    <a href="http://banchaproject.org/"><img src="http://banchaproject.org/tl_files/Bancha/images/logo.png" alt="Bancha" /></a>
    <br /><br />

	<p>
       Setup check:
    </p>
    <div id="log"></div>
    
    <br />
	
    <!-- for footer alignment -->
	<div class="push"></div> 
</div>
<div class="footer"> 
	<small>&copy; 2011-2012 Roland Sch&uuml;tz. <a href="http://banchaproject.org/impressum.html">Impressum</a>. Icons by <a href="http://www.famfamfam.com/lab/icons/silk/" target="_blank">FamFamFam</a>.</small>
</div>


<!-- include ExtJS -->
<script type="text/javascript" src="http://extjs.cachefly.net/extjs/4.0.1/ext-all.js"></script>

<!-- test setup -->
<script type="text/Javascript">
/*jslint browser: true, vars: true, plusplus: false, white: true, sloppy: true */
/*jshint bitwise:true, curly:true, eqeqeq:true, forin:true, immed:true, latedef:true, newcap:true, noarg:true, noempty:true, regexp:true, undef:true, trailing:true, strict:false */
/*global Ext:false, Bancha:false, window:false, alert:false */

if(typeof window.Ext !== 'object') {
	alert('This script requires a internet connection to load Ext Core.');
}

var BanchaSetup = {
	
	
	// helper functions
	log: Ext.get('log'),
	writeLog: function(result,name,/*optional*/ explanation) {
		this.log.insertHtml(
			'beforeEnd',
			'<img src="http://docs.banchaproject.org/setup-check/icons/' +(result==='party' ? 'cake.png" alt="ALL DONE" />' : (result==='warn' ? 'error.png" alt="WARNING" />' : (result===true ? 'accept.png" alt="OK" />' : 'cancel.png" alt="ERROR" />')))+
			' '+name+
			((explanation && result!==true) ? '<div class="explanation">'+explanation+'</div>' : '')+
			'<br>'
		);
	},
	bugReportText: 'Please <a href="https://github.com/Bancha/Bancha/issues" target="_blank">report this bug</a>, this should not happen.',
	loadScript: function(location,callback) {
		// check if the file exists (404)
		Ext.Ajax.request({
			url: location,
			success:function(ajaxResponse) {
				BanchaSetup.loadScript_fileExists(location,function(isLoaded) {
					callback(isLoaded,ajaxResponse);
				});
			},
			failure:function(ajaxResponse) {
				callback(false,ajaxResponse);
			}
		});
	},
	loadScript_fileExists: function(location,callback) {
		var script_tag = document.createElement('script'),
			isLoaded = false,
			executedCallback = false;
		
		// load
		script_tag.setAttribute('type', 'text/javascript');
		script_tag.setAttribute('src', location);
		document.getElementsByTagName('head')[0].appendChild(script_tag);
		
		script_tag.onload = script_tag.onerror = script_tag.onreadystatechange = function() {
			if(!this.readyState ||
					this.readyState === "loaded" || this.readyState === "complete") {
				// script successfully loaded
				isLoaded = true;
			}
			
			// no first state change
			if(!executedCallback) {
				callback(isLoaded);
			}
		};
	},
	
	
	// setup checks
	checkSetup: function() {
		
		// check if it is opened from right location
		if(document.location.href && document.location.href.substr(-24).toLowerCase()!=="/bancha/setup-check.html") {
			alert('Please only open this page with the bancha-prefix:\n /bancha/setup-check.html');
			return;
		}
		
		// try to load Bancha
		BanchaSetup.loadScript('js/Bancha.js',BanchaSetup.checkSetup_onBanchaIsLoaded);
	},
	checkSetup_onBanchaIsLoaded: function(isLoaded,ajaxResponse) {
		
		// check if Bancha is loaded
		BanchaSetup.writeLog(isLoaded,'Load Bancha library', [
			'<b>'+ajaxResponse.status+': Could not load the Bancha library. </b><br />',
			'This is most likely a server configuration problem, please check why the JavaScript ',
			'file is not available here: <a href="js/Bancha.js" target="_blank">js/Bancha.js</a><br /><br />',

			'If you see an error message "Controller class JsController could not be found.", please check ',
			'if the file Plugin/Bancha/webroot/js/Bancha.js exists.<br /><br/>',
			'If you think this is a bug, please <a href="https://github.com/Bancha/Bancha/issues" ',
			'target="_blank">report it</a>, appending the output of js/Bancha.js'
			].join(''));
		if(isLoaded===false) {
			return;
		}
		
		// check if Bancha lib works
		var executed = (typeof window.Bancha === 'object');
		BanchaSetup.writeLog(executed,'Execute Bancha library', [
			'<b>Could not execute the Bancha library</b><br />',
			'There seems to be an JavaScript error inside Plugin/Bancha/webroot/js/Bancha.js. ',
			'First check is you can really see JavaScript Code opening ',
			'<a href="js/Bancha.js" target="_blank">js/Bancha.js</a>. <br /><br />',
			'If not and you think this is a bug, please <a href="https://github.com/Bancha/Bancha/issues" ',
			'target="_blank">report it</a>, appending the output of js/Bancha.js.<br /><br />',
			'If you see some JavaScript this error most likely doesn\'t exist in the official version. ',
			'Please make sure you are using the official Bancha library. If so: ',
			BanchaSetup.bugReportText].join(''));
		if(executed===false) {
			return;
		}
		
		// try to load the Bancha remote api
		BanchaSetup.loadScript('../bancha-api.js',BanchaSetup.checkSetup_onBanchaRemoteApiIsLoaded);
	},
	checkSetup_onBanchaRemoteApiIsLoaded: function(isLoaded,ajaxResponse) {

		var instructions = [
			'You most likely did not correctly installed Bancha, please check ',
			'<a href="http://docs.banchaproject.org/resources/Installation.html" target="_blank">Installation: Step 2</a> ',
			'and make sure there are no cake errors in the <a href="../bancha-api.js" target="_blank">Remote API</a>.',
			'<br /><br />',
			'If you think this is a bug, please <a href="https://github.com/Bancha/Bancha/issues" ',
			'target="_blank">report it</a>, appending the output of teh Remote API above.<br /><br />',
			'Otherwise write to support@banchaproject.org'].join('');
		
		// check if Bancha remote api is loaded
		if(ajaxResponse.status===404) {
			BanchaSetup.writeLog(isLoaded,'Load Bancha Remote API',
				'<b>'+ajaxResponse.status+': Could not load the Bancha Remote API</b><br />'+instructions);
		} else {
			BanchaSetup.writeLog(isLoaded,'Load Bancha Remote API',
				ajaxResponse.status+': Could not load the Bancha Remote API, probably your database connection doesn\'t work, see the <a href="../bancha-api.js" target="_blank">Remote API</a> for errors.<br/>If this doesn\'t help: '+BanchaSetup.bugReportText);
		}
		if(isLoaded===false) {
			return;
		}

		// check if Bancha lib works
		var executed = (Bancha.REMOTE_API && Bancha.REMOTE_API.actions && typeof Bancha.REMOTE_API.actions.Bancha === 'object');

		// check if the boostrap is loaded and therefore there is a namespace set
		if(!executed && ajaxResponse.responseText.indexOf('={')<19) {
			// namespace missing
			BanchaSetup.writeLog(false,'<b>Wrong CakePHP Configuration for Plugin</b>', [
				'You are missing the "bootstrap=>true" part in your configuration, please see ',
				'<a href="http://docs.banchaproject.org/resources/Installation.html" target="_blank">',
				'Installation: Step 2</a>.<br /><br />',
				instructions].join(''));
			return;
		}

		BanchaSetup.writeLog(executed,'Bancha Remote API available', 'Could not init Bancha Remote API. Please make sure you are using the official Bancha library. If so: '+BanchaSetup.bugReportText);
		if(executed===false) {
			return;
		}
		
		// check remote stubs include Bancha API
		Bancha.init();
		var banchaApiAvailable = (Bancha.RemoteStubs && Bancha.RemoteStubs.Bancha && typeof Bancha.RemoteStubs.Bancha.loadMetaData === 'function');
		BanchaSetup.writeLog(banchaApiAvailable,'Init Bancha, Bancha API available', 'Could not find Bancha API for loading model meta data. Please make sure you are using the official Bancha library. If so: '+BanchaSetup.bugReportText);
		if(banchaApiAvailable===false) {
			return;
		}
		
		// try to check bancha dispatcher
		BanchaSetup.loadScript('../bancha-dispatcher.php?setup-check=true',BanchaSetup.checkSetup_onBanchaDispatcherIsLoaded);
		
	},
	checkSetup_onBanchaDispatcherIsLoaded: function(isLoaded,ajaxResponse) {

		// check if Bancha Dispatcher is copied to webroot
		BanchaSetup.writeLog(isLoaded,'Ping Bancha Dispatcher', [
			'<b>'+ajaxResponse.status+': Could not find Bancha Dispatcher</b><br/><br/>',
			'Please copy the Bancha Dispatcher from <i>plugins/Bancha/_app/webroot/bancha-dispatcher.php</i> ',
			'into <i>app/webroot/</i>.<br/><br/>',
			'If you still have this problem check the output of <a href="../bancha-dispatcher.php" target="_blank">',
			'Bancha Dispatcher page</a>. Note, the Dispatcher works correctly if you can see the error ',
			'messsage "Missing POST Data: ...". This is expected!<br /><br />',
			'If there is no obvious clue, please <a href="https://github.com/Bancha/Bancha/issues" ',
			'target="_blank">report it</a>, including the output of the Bancha Dispatcher page.'
			].join(''));
		if(isLoaded===false) {
			return;
		}

		// check if Bancha Dispatcher is the official one
		var response = Ext.decode(ajaxResponse.responseText),
			works = response.BanchaDispatcherIsSetup===true;
		BanchaSetup.writeLog(works,'Bancha Dispatcher works', [
			'<br /><b>Could not validate the Bancha Dispatcher!!!</b><br /><br />',
			'Please copy the official Bancha Dispatcher from <i>Plugin/Bancha/_app/webroot/bancha-dispatcher.php</i> ',
			'into <i>app/webroot/</i>. <br /><br />If  you did so: '+BanchaSetup.bugReportText
			].join(''));
		if(works===false) {
			return;
		}
		
		var exposedRemoteStubs = Ext.Object.getSize(Bancha.REMOTE_API.actions)>1;
		if(exposedRemoteStubs) {
			BanchaSetup.writeLog(true,'Exposed CakePHP models and/or methods');
		}

		BanchaSetup.writeLog('party',[
			'<b>Congratulations! You have successfully installed Bancha.</b><br /><br /><br />',
			(exposedRemoteStubs ? '' : [
				'<div style="text-align:center;">',
				'You haven\'t yet exposed any models or methods in CakePHP.<br />',
				'<a href="http://docs.banchaproject.org/resources/Usage-in-CakePHP.html">',
				'Read here how to do this.</a></div>'].join(''))
			].join(''));
	}
}; //eo BanchaSetup

Ext.onReady(BanchaSetup.checkSetup,BanchaSetup);

</script>

</body>
</html>